﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using PMS.XCMG.Util;

namespace PMS.XCMG.Entity
{
    /// <summary>
    /// 设备
    /// </summary>
    public partial class Equipment : BusEntity
    {
        /// <summary>
        /// 工位ID
        /// </summary>
        public string StationId { set; get; }
        /// <summary>
        /// 设备编码
        /// </summary>
        public string Code { get; set; }
        /// <summary>
        /// 设备名称
        /// </summary>
        public string Name { get; set; }
    }

    public partial class Equipment : BusEntity
    {
        /// <summary>
        /// 工位实体
        /// </summary>
        public WorkshoStation Station { set; get; }

        public virtual List<EquipmentFaultSetting> FaultConfigs { set; get; }
    }

    /// <summary>
    /// 实体配置
    /// OnModelCreating
    /// </summary>
    public class EquipmentTypeConfig : BusEntityTypeConfig<Equipment>, IEntityTypeConfiguration<Equipment>
    {
        public override void Configure(EntityTypeBuilder<Equipment> builder)
        {
            base.Configure(builder);

            #region 主外键关系
            builder.HasOne(p => p.Station).WithMany().HasForeignKey(p => p.StationId);
            #endregion

            #region 字段属性:最大长度,是否必需,默认值
            builder.Property(p => p.StationId).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Code).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Name).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            #endregion

            #region 备注
            builder.HasComment("设备");
            builder.Property(p => p.StationId).HasComment("负责工位ID");
            builder.Property(p => p.Code).HasComment("设备编码");
            builder.Property(p => p.Name).HasComment("设备名称");
            #endregion

            #region 种子数据
            #endregion
        }
    }
}
